<?php
//start the session
session_start();
//retreve user login form
$username = $_POST['username'];
$password = $_POST['password'];
//set authencation to FALSE
$auth=0;
//include classes to retrive user information
include('class/user.php');
include('class/dbmodifier.php');
include('class/role.php');
include('class/country.php');
//make sure the form is filled
if(($username != "") and ($password != "")){
	$user = user::getUserByUsernameAndPassword($username,md5($password));
	if(isset($user)){
			$user->setSid(session_id());
			$user->getSid();
			$user->save();
			$auth = 1;
	}
}

if($auth == 1){

	//you are authenticated
	$_SESSION['ISADMIN'] = $user->getRole()->isAdmin();
	$_SESSION['ISCLIENT'] =  $user->getRole()->isClient();
	$_SESSION['ISWORKER'] =  $user->getRole()->isAgent();
	$_SESSION['loginError']=0;
	$_SESSION['USEROBJ']=$user;	
	header("Location: dashboard.php");
}else{
	$_SESSION['loginError']=0;
	header("Location: index.php");
}

?>